package halma;

import java.util.Scanner;

import org.apache.mina.core.session.IoSession;

import cn.edu.zjut.mina.bean.StandardFormat;
import cn.edu.zjut.mina.protocal.JMessageProtocalRes;
import cn.edu.zjut.mina.protocal.ProtocalRegulation;
import cn.edu.zjut.mina.util.GsonUtils;
import cn.edu.zjut.mina.util.ResultInfoConstUtils;
//初始化游戏Json-------{"functionCode":901,"content":"{}"}
//移动Json----------{"functionCode":902,"content":"{\"start\":{\"x\":9,\"y\":12,\"type\":0},\"end\":{\"x\":9,\"y\":12,\"type\":2}}"}
//ai------------------{"functionCode":903,"content":"{}"}
public class Test {

	public static Game game;

	public static void start(StandardFormat inJson, IoSession session) {
		// TODO Auto-generated method stub

		game = new Game(2);
		JMessageProtocalRes res = new JMessageProtocalRes();
		StandardFormat outJson = new StandardFormat();
		String datas;
		outJson.result = true;
		outJson.resultInfo = ResultInfoConstUtils.init;
		res.setResultCode(ProtocalRegulation.init);
		datas = GsonUtils.beanToJson(outJson).trim();
		res.setContent(datas);
		session.write(res);
	
	}

	public static void ai(StandardFormat inJson, IoSession session) {
		Coordinate[] c=new Coordinate[2];
		c =game.runAi(2);
		JMessageProtocalRes res = new JMessageProtocalRes();
		StandardFormat outJson = new StandardFormat();
		String datas;
		outJson.result = true;
		outJson.start=c[0];
		outJson.end=c[1];
		outJson.resultInfo = ResultInfoConstUtils.ai;
		res.setResultCode(ProtocalRegulation.ai);
		datas = GsonUtils.beanToJson(outJson).trim();
		res.setContent(datas);
		session.write(res);
		
	}

	public static void move(StandardFormat inJson, IoSession session) {
		Coordinate start=inJson.start;
		Coordinate end=inJson.end;
		game.move(start,end);
		JMessageProtocalRes res = new JMessageProtocalRes();
		StandardFormat outJson = new StandardFormat();
		String datas;
		outJson.result = true;
		outJson.resultInfo = ResultInfoConstUtils.Move;
		res.setResultCode(ProtocalRegulation.move);
		datas = GsonUtils.beanToJson(outJson).trim();
		res.setContent(datas);
		session.write(res);
	}
}
